<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class Eyeworx_ContactLensPtntExpManager extends Module
{
    private $rb = null;

    public function construct()
    {
        $solutions_ptnt_recordset = new Eyeworx_ContactLensPtntExpManager_RBO_ContactLensPtntExps();
        $this->rb = $solutions_ptnt_recordset->create_rb_module($this);
        $this->rb->set_button('');
    }

    public function applet($conf, & $opts)
    {
//        DB::Execute("DELETE from eyeworx_patient_birthday_data_1");
//        DB::GetAll("SELECT patient as patient, IF(date_format(f_birth_date, '%e') = date_format(curdate(), '%e'), date_format(f_birth_date, '%M %e (Today)'), date_format(f_birth_date, '%M %e (%W)')) as bdate, TIMESTAMPDIFF(YEAR,f_birth_date,CURDATE()) as age, f_contact_number as cno from eyeworx_patient_data_1 where month(f_birth_date) = month(curdate()) and day(f_birth_date) >= day(curdate()) order by date_format(f_birth_date, '%d') asc");
//        $patients = DB::GetAll("SELECT f_patient as patient, IF(date_format(f_birth_date, '%e') = date_format(curdate(), '%e'), date_format(f_birth_date, '%M %e (Today)'), date_format(f_birth_date, '%M %e (%W)')) as bdate, TIMESTAMPDIFF(YEAR,f_birth_date,CURDATE()) as age, f_contact_number as cno from eyeworx_patient_data_1 where month(f_birth_date) = month(curdate()) and day(f_birth_date) >= day(curdate()) order by date_format(f_birth_date, '%d') asc");
//
//        $patient_birthday_recordset_accessor = new RBO_RecordsetAccessor('eyeworx_patient_birthday');
//        for ($x = 0; $x < count($patients); $x++) {
//            $patient = $patients[$x];
//            $r = $patient_birthday_recordset_accessor->new_record();
//            $r->patient = $patient['patient'];
//            $r->contact_number = $patient['cno'];
//            $r->birth_date = $patient['bdate'];
//            $r->age = $patient['age'];
//            $r->save();
//        }
        $solutions_ptnt_recordset = new Eyeworx_ContactLensPtntExpManager_RBO_ContactLensPtntExps();
        $opts['go'] = false;
        $rb = $solutions_ptnt_recordset->create_rb_module($this);
        $crits = array();
        $conds = array(
            array(array('field' => 'patient', 'width' => 35),
                array('field' => 'contact_number', 'width' => 20),
                array('field' => 'birth_date', 'width' => 35),
                array('field' => 'age', 'width' => 10)
            ),
            $crits,
            array(),
            array(),
            1000,
            array('actions_edit' => false, 'actions_info' => false),
            & $opts
        );

        $this->display_module($rb, $conds, 'mini_view');
    }

    public function body()
    {
        $this->display_module($this->rb);
    }

    public function caption()
    {
        return 'Patient - Contact Lens Expiration List';
    }

}